package com.fsy.spring.annotation;

import com.fsy.spring.annotation.Bean.BaseResult;
import com.fsy.spring.annotation.Bean.Task;

/**
 * Created by shuangyu.feng on 2017/8/9.
 */
public class TaskExecutor {

	private static final String TASK_TYPE = "UserNameChanged";

	public  BaseResult execute(Task task){
		String taskType=task.getTaskType();
		if (TaskHandlerRegister.getTaskHandler(taskType) == null) {
			throw new RuntimeException("can't find taskHandler,taskType=" + taskType);
		}
		AbstractTaskHandler abstractHandler = TaskHandlerRegister.getTaskHandler(taskType);
		return abstractHandler.execute(task);
	}

	public static void main(String[] args){
		Task task = new Task();
		task.setTaskId("1");
		task.setTaskType(TASK_TYPE);
		TaskExecutor taskExecutor = new TaskExecutor();
		taskExecutor.execute(task);
	}
}
